home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / TextHarvest / TextHarvest-Install.exe / {app} / ScrExercise.txt < prev    next >
Text File  |  2005-02-22  |  73KB  |  2,060 lines

  1. ;===============================================================================
  2. ; The Exercise Script
  3. ;===============================================================================
  4. ;
  5. ;   This is the actual script used by Pinnacle Software to verify that
  6. ;   the Parse-O-Matic Scripting commands are working properly. We run
  7. ;   this script after we make changes to the Parsing or Scripting engines,
  8. ;   to ensure that the commands are still functioning correctly.
  9. ;
  10. ;   To try out this script, use any text input file -- it only reads the
  11. ;   first line. The output (when everything is working fine) is simply
  12. ;   a tidy list of scripting commands and concepts.
  13. ;
  14. ;   You can refer to this file if you are ever in doubt about the way
  15. ;   that a command should be used.
  16. ;
  17. ;===============================================================================
  18. ; Config
  19. ;===============================================================================
  20.  
  21. Config
  22.   $CfgEnableOptionX = 'N'
  23.   $CfgEnableOptionY = 'N'
  24.   $CfgCaptionZ      = '&Test flag'
  25.   $CfgHintZ         = 'Leave blank - see Help for explanation'
  26.   $CfgCopyright     = 'Copyright ⌐ 2003, 2005 by Pinnacle Software'
  27.   $CfgVersion       = '2.00.00'
  28.   $CfgProgrammer    = 'Timothy Campbell'
  29.   $CfgEmail         = 'info@parse-o-matic.com'
  30.   $CfgLicense       = 'This script may be used, at no charge, with any ' >>
  31.     'script-enabled Parse-O-Matic application, subject to any additional ' >>
  32.     'licensing requirements of such application.'
  33.   $CfgDefaultIFN    = 'ThingsToDoUnix.txt';
  34.   $CfgDefaultOFN    = 'Temp.txt';
  35. End
  36.  
  37. ;===============================================================================
  38. ; TaskInit
  39. ;===============================================================================
  40.  
  41. TaskInit
  42.   ;-----------------------------------------------------------------------------
  43.   ; Check to see if /NI is in OptionZ. If so, we suppress most of the
  44.   ; informational output. This parameter is used for internal testing at
  45.   ; Pinnacle Software and may change from version to version of this script.
  46.   ; Under normal circumstances, variable PT ("Pinnacle Test") is set to 'N'.
  47.   ;-----------------------------------------------------------------------------
  48.   TestOptZ = $OptionZ
  49.   PT = 'N'
  50.   TestOptZ = ChangeCase TestOptZ
  51.   Begin TestOptZ ^ '/NI'
  52.     PT = 'Y'
  53.     Change   TestOptZ '/NI' ''
  54.   End
  55.   ;-----------------------------------------------------------------------------
  56.   ; Make sure all the option boxes are empty
  57.   ;-----------------------------------------------------------------------------
  58.   Call EnsureOptionEmpty $CaptionZ #13 TestOptZ
  59.   OutEnd '.ùùùùùùùùùùùùùùù.'
  60.   OutEnd '|   EXERCISE    |'
  61.   OutEnd '+ùùùùùùùùùùùùùùù+'
  62.   OutEnd '| TaskInit      |'
  63.   ;-----------------------------------------------------------------------------
  64.   ; This next demonstration uses Done to leave this section and move on to
  65.   ; the next step (i.e. FileInit). In an actual script, though, it would be
  66.   ; pointless to have an unconditional Done in the TaskInit section.  You
  67.   ; normally leave a step for a reason, or simply let the code run on until
  68.   ; its final End statement.
  69.   ; Note that "Done", when used in the Main step, is not equivalent to
  70.   ; NextStep. The "Flow Control" section of the Parse-O-Matic Scripting
  71.   ; manual explains this in more detail.
  72.   ;-----------------------------------------------------------------------------
  73.   Done                                 ; Leave this section
  74.   OutEnd 'This line will not appear'   ; This line won't show up in output
  75. End
  76.  
  77. ;===============================================================================
  78. ; FileInit
  79. ;===============================================================================
  80.  
  81. FileInit
  82.   OutEnd '| FileInit      |'
  83.   OutEnd '+ ù ù ù ù ù ù ù +'
  84.   ;-----------------------------------------------------------------------------
  85.   ; This next demonstration uses NextStep to leave this section and move on
  86.   ; to the next step (i.e. Main). In an actual script, though, it would be
  87.   ; pointless to have an unconditional NextStep in the FileInit section.
  88.   ; You normally leave a step for a reason, or simply let the code run on
  89.   ; until its final End statement.
  90.   ;-----------------------------------------------------------------------------
  91.   NextStep                             ; Leave this section
  92.   OutEnd 'This line will not appear'   ; This line won't show up in output
  93. End
  94.  
  95. ;===============================================================================
  96. ; FileDone
  97. ;===============================================================================
  98.  
  99. FileDone
  100.   OutEnd '+ ù ù ù ù ù ù ù +'
  101.   OutEnd '| FileDone      |'
  102. End
  103.  
  104. ;===============================================================================
  105. ; TaskDone
  106. ;===============================================================================
  107.  
  108. TaskDone
  109.   OutEnd '| TaskDone      |'
  110.   OutEnd '|ùùùùùùùùùùùùùùù|'
  111.   OutEnd '|   FINISHED    |'
  112.   OutEnd '''ùùùùùùùùùùùùùùù'''
  113. End
  114.  
  115. ;===============================================================================
  116. ; The Again Command (see "The Begin/Else/End/Again Commands" for tests)
  117. ;===============================================================================
  118.  
  119. If PT = 'N' OutEnd '| Again         |'  ; Included here for completeness
  120.  
  121. ;===============================================================================
  122. ; AlphaNumPatt
  123. ;===============================================================================
  124.  
  125. If PT = 'N' Output '| AlphaNumPatt  |'
  126.  
  127. Z = '1234-Ba/9'
  128. X = AlphaNumPatt Z                     ; Generate the pattern
  129. If X <> 'NNNN-AA/N'   Odb 'A' X
  130.  
  131. Z = '#AbA-33:4'
  132. X = AlphaNumPatt Z                     ; Different layout
  133. If X <> '#AAA-NN:N'   Odb 'B' X
  134.  
  135. Z = ' @XYZ-99:9 '                      ; Note the spaces on either side
  136. X = AlphaNumPatt Z
  137. If X <> ' @AAA-NN:N ' Odb 'C' X
  138.  
  139. Z = ' %A9-CD-99 '
  140. X = AlphaNumPatt Z 'B '                ; Trim spaces on both sides
  141. If X <> '%AN-AA-NN'   Odb 'D' X
  142.  
  143. Z = ' A2-B3-D4 '
  144. X = AlphaNumPatt Z 'A A-'              ; Trim spaces and dashes
  145. If X <> 'ANANAN'      Odb 'E' X
  146.  
  147. Z = '12-34-56'                         ; Example from the Help file
  148. X = AlphaNumPatt Z
  149. If X <> 'NN-NN-NN'   Odb 'F' X
  150.  
  151. Z = ' $12.34 '                         ; Example from the Help file
  152. X = AlphaNumPatt Z
  153. If X <> ' $NN.NN '   Odb 'G' X
  154.  
  155. Z = 'AB 1234'                          ; Example from the Help file
  156. X = AlphaNumPatt Z
  157. If X <> 'AA NNNN'    Odb 'H' X
  158.  
  159. Z = ' XY 999 '                         ; Example from the Help file
  160. X = AlphaNumPatt Z 'B '
  161. If X <> 'AA NNN'     Odb 'I' X
  162.  
  163. Z = ' XY 999 '
  164. X = AlphaNumPatt Z 'A '
  165. If X <> 'AANNN'      Odb 'J' X
  166.  
  167. If PT = 'N' OutNull
  168.  
  169. ;===============================================================================
  170. ; Arrays
  171. ;===============================================================================
  172.  
  173. If PT = 'N' Output '| Arrays        |'
  174.  
  175. ;-------------------------------------------------------------------------------
  176. ; First we will demonstrate arrays with numeric indices
  177. ;-------------------------------------------------------------------------------
  178.  
  179. X = 'ABCDE' >>                         ; Demonstration of line continuation
  180.     'FGHIJ'                            ; We could have done X = 'ABCDEFGHIJ'
  181.  
  182. Cntr = 0
  183. Begin
  184.   Cntr = Cntr+
  185.   MyArray(Cntr) = Cols X Cntr Cntr     ; Set MyArray(1) through MyArray(6)
  186. Again Cntr #< 6                        ; Repeat if we haven't reached 6
  187.  
  188. MyArray = 'XYZ'                        ; Has no effect; it's not an array
  189.  
  190. If MyArray(1) <> 'A' Odb '1A' MyArray(1)
  191. If MyArray(2) <> 'B' Odb '1B' MyArray(2)
  192. If MyArray(3) <> 'C' Odb '1C' MyArray(3)
  193. If MyArray(4) <> 'D' Odb '1D' MyArray(4)
  194. If MyArray(5) <> 'E' Odb '1E' MyArray(5)
  195. If MyArray(6) <> 'F' Odb '1F' MyArray(6)
  196.  
  197. ;-------------------------------------------------------------------------------
  198. ; When we inspect an array element that was never assigned a value, it
  199. ; returns the special variable $NotDefined, which is usually set to '[ND]'.
  200. ; You can set $NotDefined to some other value if you wish.
  201. ;-------------------------------------------------------------------------------
  202.  
  203. Cntr = 7
  204. If MyArray(Cntr) <> $NotDefined Odb '1Z' MyArray(Cntr)
  205.  
  206. ;-------------------------------------------------------------------------------
  207. ; A gratuitously complex example of arrays in action
  208. ;-------------------------------------------------------------------------------
  209.  
  210. Jx = 'Test'
  211. Kx = 1
  212. Lx = 3
  213. MyArray(Jx) = 'abcdefghij'
  214. MyArray(Kx) = 2
  215. MyArray(Lx) = 4
  216. MyArray(Lx) = Cols MyArray(Jx) MyArray(Kx) MyArray(Lx)
  217. If MyArray(Jx)[2 3] <> 'bc'  Odb '2A' MyArray(Jx)[2 3]
  218. If MyArray(Kx) <> '2'        Odb '2B' MyArray(Kx)
  219. If MyArray(Lx) <> 'bcd'      Odb '2C' MyArray(Lx)
  220. If Jx <> 'Test'              Odb '2D' Jx
  221. If Kx <> 1                   Odb '2E' Kx
  222. If Lx <> 3                   Odb '2F' Lx
  223.  
  224. ;-------------------------------------------------------------------------------
  225. ; Demonstrating arrays with text indices
  226. ;-------------------------------------------------------------------------------
  227.  
  228. TextIndex = 'Cat'
  229. MyArray(TextIndex) = 'Fluffy'
  230. TextIndex = 'Dog'
  231. MyArray(TextIndex) = 'Fido'
  232.  
  233. If MyArray('Cat') <> 'Fluffy' Odb '4A' MyArray('Cat')
  234. If MyArray('Dog') <> 'Fido'   Odb '4B' MyArray('Dog')
  235.  
  236. ;-------------------------------------------------------------------------------
  237. ; Demonstrating the use of arrays with a command that alters the variable
  238. ;-------------------------------------------------------------------------------
  239.  
  240. KeepChar MyArray('Dog') '/F/o'
  241. If MyArray('Dog') <> 'Fo'     Odb '5' MyArray('Dog')
  242.  
  243. ;-------------------------------------------------------------------------------
  244. ; The variable named MyArray was set earlier. It does not have any effect on
  245. ; the arrays because it does not look like an array (i.e. the name is not
  246. ; followed by an index in parentheses).
  247. ;-------------------------------------------------------------------------------
  248.  
  249. If MyArray <> 'XYZ'  Odb 'Z' MyArray   ; Variable MyArray is NOT an array
  250.  
  251. If PT = 'N' OutNull                    ; End of this test
  252.  
  253. ;===============================================================================
  254. ; The Begin/Else/End/Again Commands
  255. ;===============================================================================
  256.  
  257. X = '| Begin         |'
  258.  
  259. Begin PT = 'N'                         ; PT is used for testing; normally 'N'
  260.   Begin X = X                          ; Comparison is true
  261.     Output X[1 2]                      ; This will be executed
  262.     Output X[3 4]                      ; This will be executed
  263.   Else
  264.     Odb 'A'                            ; This will not be executed
  265.   End
  266. End
  267.  
  268. Begin PT = 'N'                         ; PT is used for testing; normally 'N'
  269.   Begin X <> X                         ; Comparison is false
  270.      Odb 'B'                           ; This will not be executed
  271.   Else
  272.     Output X[5 6]                      ; This will be executed
  273.   End
  274. End
  275.  
  276. Begin PT = 'N'                         ; PT is used for testing; normally 'N'
  277.   XLen = Len X
  278.   Counter = 6
  279.   Begin                                ; Loop through the rest
  280.     Counter = Counter+
  281.     Z = Cols X Counter Counter
  282.     Output Z
  283.   Again Counter #< XLen                ; Stop when we've sent the last char
  284. End
  285.  
  286. X = 100
  287. Begin 'A' = 'A'
  288.   X = X+                               ; This will be executed
  289.   Begin 'A' = 'A'
  290.     X = X+                             ; This will be executed
  291.   End
  292.   Counter = 0
  293.   Begin
  294.     Counter = Counter+
  295.     X = X+                             ; This will happen 3 times
  296.   Again Counter #< 3
  297.   Begin 'A' = 'Z'
  298.     X = X-                             ; This will not be executed
  299.   Else
  300.     X = X+                             ; This will be executed
  301.     Begin 1 <> 3
  302.       X = X+                           ; This will be executed
  303.     Else
  304.       X = X-                           ; This will not be executed
  305.     End
  306.   End
  307. Else
  308.   X = X-                               ; This will not be executed
  309.   Begin 'A' = 'A'
  310.     X = 'Oops'                         ; This will not be executed
  311.   End
  312. End
  313. If X <> '107'   Odb 'C' X
  314.  
  315. X = 0
  316. Begin
  317.   X = X+
  318. Again X #< 10                          ; Test at bottom of loop
  319. If X <> 10      Odb 'D' X
  320.  
  321. X = 0
  322. Begin X #< 11                          ; Test at top of loop
  323.   X = X+
  324. Again
  325. If X <> 11      Odb 'E' X
  326.  
  327. Z = 'Test'
  328. X = 0
  329. Begin Z = 'Test'                       ; Conditional repeat-until
  330.   X = X+
  331. Again X #< 12
  332. If X <> 12      Odb 'F' X
  333.  
  334. Z = 'No Test'
  335. X = 0
  336. Begin Z = 'Test'                       ; Skipped conditional repeat-until
  337.   X = X+
  338. Again X #< 13
  339. If X <> 0       Odb 'G' X
  340.  
  341. Z = 'Test'
  342. X = 0
  343. Begin Z = 'Test'                       ; Conditional repeat-until
  344.   X = X+
  345.   If X = 3 Z = 'No Test'               ; Interrupt the loop at the top
  346. Again X #< 14
  347. If X <> 3       Odb 'H' X
  348.  
  349. If PT = 'N' OutNull                    ; End of this test
  350.  
  351. ;===============================================================================
  352. ; The Break Command
  353. ;===============================================================================
  354.  
  355. If PT = 'N' Output '| Break         |'
  356.  
  357. X = 0
  358. Begin X #< 10                          ; Test at top of loop
  359.   X = Calc X + 2
  360.   If X #= 6 Break
  361. Again
  362. If X <> 6    Odb 1 X
  363.  
  364. X = 0
  365. Begin
  366.   X = Calc X + 2
  367.   If X #= 8 Break
  368. Again X #< 10                          ; Test at bottom of loop
  369. If X <> 8    Odb 2 X
  370.  
  371. X = 0
  372. Begin
  373.   X = Calc X + 2
  374.   If X #= 12 Break                     ; This will never trigger
  375. Again X #< 10
  376. If X <> 10   Odb 3 X
  377.  
  378. X = 0
  379. Begin
  380.   Inc X
  381.   If X #> 4 Break                      ; Proceeds to the second Again along
  382.   Begin
  383.     Inc X
  384.   Again X #< 4
  385. Again                                  ; Without Break would loop forever
  386. If X <> 5  Odb 4 X
  387.  
  388. ;-------------------------------------------------------------------------------
  389. ; The following code would not work because Break looks for an Again
  390. ; command somewhere within the same set of Begin/End/Again blocks.
  391. ;-------------------------------------------------------------------------------
  392. ;X = 15
  393. ;Begin X = 15
  394. ;  X = X+
  395. ;  If X = 30 Break
  396. ;  X = X+
  397. ;End
  398.  
  399. ;-------------------------------------------------------------------------------
  400. ; The following command is "out of context" because it is not in a Begin
  401. ; block.  If it is uncommented, it will cause a script error.
  402. ;-------------------------------------------------------------------------------
  403. ;Break
  404.  
  405. If PT = 'N' OutNull                    ; End of this test
  406.  
  407. ;===============================================================================
  408. ; The Calc Command
  409. ;===============================================================================
  410.  
  411. If PT = 'N' Output '| Calc          |'
  412.  
  413. X = Calc 1 + 2                         ; Addition
  414. If X <> 3       Odb 1 X
  415.  
  416. X = Calc ' 3 ' - ' 4 '                 ; Subtraction with spurious spaces
  417. If X <> -1      Odb 2 X
  418.  
  419. X = Calc '#3,000' * 'Number 4'         ; Multiplication with lots of noise
  420. If X <> 12000   Odb 3 X
  421.  
  422. X = Calc 12 / 2                        ; Integer division
  423. If X <> 6       Odb 4 X
  424.  
  425. X = Calc 13 / 2                        ; Integer division
  426. If X <> 6       Odb 5 X                ; Remainder is discarded
  427.  
  428. X = Calc 100 / 99                      ; Integer division
  429. If X <> 1       Odb 6 X                ; Remainder is discarded
  430.  
  431. X = Calc 999 / 1000                    ; Integer division
  432. If X <> 0       Odb 7 X                ; Remainder is discarded
  433.  
  434. X = Calc 100 Highest 10                ; Pick the highest number
  435. If X <> 100     Odb 8 X
  436.  
  437. X = Calc 200 Lowest  20                ; Pick the lowest number
  438. If X <> 20      Odb 9 X
  439.  
  440. If X = 20 Z = Calc X * 2               ; A conditional calculation
  441. If Z <> 40      Odb 'A' Z
  442.  
  443. If PT = 'N' OutNull                    ; End of this test
  444.  
  445. ;===============================================================================
  446. ; The CalcReal Command (see also: Rounding)
  447. ;===============================================================================
  448.  
  449. If PT = 'N' Output '| CalcReal      |'
  450.  
  451. X = CalcReal 1 + 2.14                  ; Addition
  452. If X <> 3.14             Odb 1 X
  453.  
  454. X = CalcReal ' 3.1 ' - ' 4.3 '         ; Subtraction with spurious spaces
  455. If X <> -1.20            Odb 2 X
  456.  
  457. X = CalcReal '#30.001' * 'XXX 4' 3     ; Lots of non-numeric noise
  458. If X <> 120.004          Odb 3 X
  459.  
  460. X = Calc 12 / 2                        ; Division to 2 decimal places
  461. If X #<> 6.000           Odb 4 X       ; Note use of #<> with 3 decimals here
  462.  
  463. X = CalcReal 13 / -2                   ; Division
  464. If X #<> -6.5            Odb 5 X       ; Note use of #<> with 1 decimal here
  465.  
  466. X = CalcReal 100 / 99 2                ; Division to 2 decimal places
  467. If X #<> 1.01            Odb 6 X
  468.  
  469. X = CalcReal 100 / 99 4                ; Division to 4 decimal places
  470. If X <> 1.0101           Odb '7A' X
  471.  
  472. X = CalcReal 100 / 99 5                ; Division to 5 decimal places
  473. If X <> 1.01010          Odb '7B' X
  474.  
  475. X = CalcReal 100 / 99 9                ; Division to 9 decimal places
  476. If X <> 1.010101010      Odb '7C' X
  477.  
  478. X = CalcReal 100 Highest 100.01 3      ; Pick the highest number
  479. If X <> 100.010          Odb 8 X
  480.  
  481. X = CalcReal 200. Lowest  20.0         ; Pick the lowest number
  482. If X <> 20.00            Odb 9 X       ; Note that X <> 20 would fail
  483.  
  484. X = CalcReal 200. Lowest  20.0         ; Pick the lowest number
  485. If X #<> 20              Odb 'A' X     ; Here the #<> is mixing real/integer
  486.  
  487. X = CalcReal 200. Lowest  20.0 '0'     ; Pick the lowest number
  488. If X <> 20.              Odb 'B' X      ; Zero decimal places
  489.  
  490. X = CalcReal 7 / 3 'Float'             ; We'll get whatever we can
  491. If X[1 10] <> 2.33333333 Odb 'C' X
  492.  
  493. If PT = 'N' OutNull                    ; End of this test
  494.  
  495. ;===============================================================================
  496. ; The Call Command
  497. ;===============================================================================
  498.  
  499. If PT = 'N' Output '| Call          |'
  500.  
  501. Call MyProcedure                       ; Simple call to a procedure
  502. If MyProcedure <> 'Hello' >>
  503.   Odb 'B' MyProcedure
  504. If X <> 'Set by MyProcedure' >>
  505.   Odb 'C' X
  506.  
  507. Cntr = 0
  508. Begin
  509.   Call AddCntr                         ; Calling within a loop
  510. Again Cntr #< 5
  511. If Cntr #<> 5        Odb 'D' Cntr
  512.  
  513. Cntr = 0
  514. Call ProcInProc1                       ; A procedure that calls another one
  515. If Cntr #<> 3        Odb 'E' Cntr
  516.  
  517. X = ''
  518. If X = '' Call ProcInProc2             ; A similar example
  519. If X <> 'AAAAAA'     Odb 'F' X
  520.  
  521. Call ParmProc 'A' '/' 'B'              ; Set ParmProc to 'A/B' then call it
  522. If ParmProc <> 'AB'  Odb 'G' ParmProc
  523.  
  524. If PT = 'N' OutNull                    ; End of this test
  525.  
  526. ;===============================================================================
  527. ; The Change Command
  528. ;===============================================================================
  529.  
  530. If PT = 'N' Output '| Change        |'
  531.  
  532. X = 'ABCD'
  533. Change X 'BC' 'ZZ'                     ; Single replacement
  534. If X <> 'AZZD'        Odb 1 X
  535.  
  536. X = 'ABCBCD'
  537. Change X 'BC' 'ZZ'                     ; Multiple replacements
  538. If X <> 'AZZZZD'      Odb 2 X
  539.  
  540. X = 'ABCD'
  541. Change X 'BC' ''                       ; Replace with null
  542. If X <> 'AD'          Odb 3 X
  543.  
  544. X = 'ABCD'
  545. Change X 'Z' 'XYZ'                     ; Replacement text not found
  546. If X <> 'ABCD'        Odb 5 X
  547.  
  548. X = 'ABCD'
  549. Change X '' 'ZZ'                       ; Replace nothing
  550. If X <> 'ABCD'        Odb 6 X
  551.  
  552. X = ' 1   / 2 / 3 '
  553. Change X ' /' '/'                      ; This must be done several times
  554. If X <> ' 1/ 2/ 3 '   Odb 7 X          ; until the change is complete
  555.  
  556. X = ' 1   / 2 / 3 '
  557. Change X ' /' '/' 'OnePass'            ; Here we say to do it only once
  558. If X <> ' 1  / 2/ 3 ' Odb 8 X
  559.  
  560. X = 'AABCD'
  561. Change X 'A' 'AA' 'MultiPass'          ; If repeated, this would never end!
  562. If X <> 'AAAABCD'     Odb 9 X          ; Thus, Change only does it once
  563.  
  564. If PT = 'N' OutNull                    ; End of this test
  565.  
  566. ;===============================================================================
  567. ; The ChangeCase Command
  568. ;===============================================================================
  569.  
  570. If PT = 'N' Output '| ChangeCase    |'
  571.  
  572. X = 'Fred Jones'
  573. Z = ChangeCase X                       ; Default to uppercase
  574. If Z <> 'FRED JONES'    Odb 1 Z
  575.  
  576. X = 'FRED Jones'
  577. Z = ChangeCase X 'Lowercase'           ; Convert to lowercase
  578. If Z <> 'fred jones'    Odb 2 Z
  579.  
  580. X = 'fred jones'
  581. Z = ChangeCase X 'Capitalize'          ; Convert to soft caps
  582. If Z <> 'Fred Jones'    Odb 3 Z
  583.  
  584. X = 'FRED jones'
  585. Z = ChangeCase X 'Capitalize'          ; Convert to soft caps
  586. If Z <> 'FRED Jones'    Odb 5 Z
  587.  
  588. X = 'FRED jones'
  589. Z = ChangeCase X 'Hardcaps'            ; Convert to hard caps
  590. If Z <> 'Fred Jones'    Odb 6 Z
  591.  
  592. X = 'WX-XY123'
  593. Z = ChangeCase X 'Hardcaps'            ; Convert to hard caps
  594. If Z <> 'Wx-Xy123'      Odb 7 Z
  595.  
  596. X = 'wx-xy123'
  597. Z = ChangeCase X 'Capitalize'          ; Convert to soft caps
  598. If Z <> 'Wx-Xy123'      Odb 8 Z        ; Same result in this instance
  599.  
  600. X = 'wx-xy123'
  601. Z = ChangeCase X 'Uppercase'           ; Convert to uppercase
  602. If Z <> 'WX-XY123'      Odb 9 Z
  603.  
  604. X = 'Fred Jones'
  605. Z = ChangeCase X[1 4]                  ; Convert a substring to uppercase
  606. If Z <> 'FRED'          Odb 'A' Z
  607.  
  608. If PT = 'N' OutNull                    ; End of this test
  609.  
  610. ;===============================================================================
  611. ; The Cols Command
  612. ;===============================================================================
  613.  
  614. If PT = 'N' Output '| Cols          |'
  615. X = 'ABCD'                             ; Used for all tests
  616.  
  617. Z = Cols X 2 3                         ; Plain Cols command
  618. If Z <> 'BC'        Odb 1 Z
  619.  
  620. Z = Cols X '2' '3'                     ; Using quoted literals
  621. If Z <> 'BC'        Odb 2 Z
  622.  
  623. Z = Cols X '2' 3                       ; Using quoted and unquoted literals
  624. If Z <> 'BC'        Odb 3 Z
  625.  
  626. Z = Cols X 10 99                       ; Beyond right edge of data
  627. If Z <> ''          Odb 4 Z
  628.  
  629. Z = Cols X 0 99                        ; Zero as starting position means 1
  630. If Z <> 'ABCD'      Odb 5 Z
  631.  
  632. Z = Cols X -1 99                       ; Negative starting position means 1
  633. If Z <> 'ABCD'      Odb 6 Z
  634.  
  635. Z = Cols X 1 -1                        ; Negative ending position
  636. If Z <> ''          Odb 7 Z
  637.  
  638. Z = Cols X 3                           ; Copy a single character
  639. If Z <> 'C'         Odb 8 Z
  640.  
  641. If PT = 'N' OutNull                    ; End of this test
  642.  
  643. ;===============================================================================
  644. ; The CompareControl Command
  645. ;===============================================================================
  646.  
  647. If PT = 'N' Output '| CompareCtrl   |'
  648.  
  649. If 'a' <> 'A' Odb 'ERROR-A'            ; They ARE equal because case is ignored
  650. CompareCtrl 'MatchCase'
  651. If 'a' = 'A'  Odb 'ERROR-B'            ; They are NOT equal now; case matters
  652. CompareCtrl 'IgnoreCase'
  653. If 'z' <> 'Z' Odb 'ERROR-C'            ; Back to standard behaviour
  654.  
  655. If PT = 'N' OutNull                    ; End of this test
  656.  
  657. ;===============================================================================
  658. ; The Config Command (see start of script for the actual Config section)
  659. ;===============================================================================
  660.  
  661. If PT = 'N' OutEnd '| Config        |'  ; Included here for completeness
  662.  
  663. ;===============================================================================
  664. ; The Continue Command
  665. ;===============================================================================
  666.  
  667. If PT = 'N' Output '| Continue      |'
  668.  
  669. X = 0
  670. Begin X #< 10                          ; Test at top of loop
  671.   X = Calc X + 2                       ; 2, 4, 6, 8, 10
  672.   If X #< 10 Continue                  ; Jump to the Again
  673.   X = X+                               ; This makes X equal 11
  674. Again
  675. If X <> 11   Odb 1 X
  676.  
  677. X = 0
  678. Begin
  679.   X = X+                               ; 1, 2
  680.   If X #= 1 Continue                   ; Jump to Again the first time only
  681.   X = Calc X + 10                      ; This makes X equal 12
  682. Again X #< 10                          ; Test at bottom of loop
  683. If X <> 12   Odb 2 X
  684.  
  685. X = 3
  686. Begin
  687.   X = X+                               ; Now X = 4
  688.   If X #= 5 Continue                   ; This will never trigger
  689. Again X #< 4
  690. If X <> 4    Odb 3 X
  691.  
  692. X = 10
  693. Begin
  694.   X = X+                               ; Now X = 11
  695.   If X #= 11 Continue                  ; This will trigger once
  696. Again X <> 11                          ; But we stop anyway, since X = 11
  697. If X <> 11   Odb 4 X
  698.  
  699. X = 0
  700. Begin
  701.   Inc X                                ; 1, 6, 7, 8
  702.   If X #> 4 Continue                   ; Proceeds to the second Again along
  703.   Begin
  704.     Inc X 2                            ; 3, 5
  705.   Again X #< 4
  706. Again X #< 8
  707. If X <> 8  Odb 4 X
  708.  
  709. ;-------------------------------------------------------------------------------
  710. ; The following usage is somewhat odd, as it is using Continue without an
  711. ; If command. If the Begin or Again did not have a condition that could
  712. ; fail, the script would loop forever. Continue commands typically have
  713. ; an If command before them.
  714. ;-------------------------------------------------------------------------------
  715. X = 0
  716. Begin X = 0
  717.   Inc X                                ; Now X = 1
  718.   Continue                             ; Jump to the Again
  719.   Inc X 100                            ; This is never executed
  720. Again
  721. If X <> 1    Odb 'A' X
  722.  
  723. ;-------------------------------------------------------------------------------
  724. ; The following code would not work because Continue looks for an Again
  725. ; command somewhere within the same set of Begin/End/Again blocks.
  726. ;-------------------------------------------------------------------------------
  727. ;X = 3
  728. ;Begin X = 3
  729. ;  X = X+
  730. ;  If X = 4 Continue
  731. ;End
  732.  
  733. If PT = 'N' OutNull                    ; End of this test
  734.  
  735. ;===============================================================================
  736. ; The Dec Command
  737. ;===============================================================================
  738.  
  739. If PT = 'N' Output '| Dec           |'
  740.  
  741. X = 3
  742. Dec X                           ; Plain decrement
  743. If X <> 2 Odb 'A' X
  744. Dec X 3                         ; Decrement by 3
  745. If X <> -1 Odb 'B' X
  746. Dec X -5                        ; Negative decrement (equivalent to Inc X 5)
  747. If X <> 4 Odb 'C' X
  748.  
  749. ;-------------------------------------------------------------------------------
  750. ; The following would not work because Dec handles only integer values
  751. ;-------------------------------------------------------------------------------
  752. ; X = 1.3
  753. ; Dec X
  754.  
  755. If PT = 'N' OutNull             ; End of this test
  756.  
  757. ;===============================================================================
  758. ; The Done Command (these tests are usually commented out)
  759. ;===============================================================================
  760.  
  761. If PT = 'N' OutEnd '| Done          |'
  762. ;-------------------------------------------------------------------------------
  763. ; Note: Uncommenting any of the following tests will cause every line of
  764. ; the input file to be processed, since we will be skipping the rest of
  765. ; this script -- including the final Stop command.
  766. ;-------------------------------------------------------------------------------
  767. ; Done
  768. ;
  769. ; X = 'Y'
  770. ; If X = 'Y' Done
  771.  
  772. ;===============================================================================
  773. ; The Else Command (see "The Begin/Else/End/Again Commands" for tests)
  774. ;===============================================================================
  775.  
  776. If PT = 'N' OutEnd '| Else          |'  ; Included here for completeness
  777.  
  778. ;===============================================================================
  779. ; The End Command (see "The Begin/Else/End/Again Commands" for tests)
  780. ;===============================================================================
  781.  
  782. If PT = 'N' OutEnd '| End           |'  ; Included here for completeness
  783.  
  784. ;===============================================================================
  785. ; The Exit Command (see Procedure EnsureOptionEmpty for an example)
  786. ;===============================================================================
  787.  
  788. If PT = 'N' OutEnd '| Exit          |'  ; Included here for completeness
  789.  
  790. ;===============================================================================
  791. ; The Equals Command
  792. ;===============================================================================
  793.  
  794. If PT = 'N' Output '| Equals        |'
  795.  
  796. X = 'ABCD'                             ; Assignment of a text literal
  797. If X <> 'ABCD'       Odb 1 X
  798.  
  799. X = 3.14                               ; Assignment of a numeric literal
  800. If X <> '3.14'       Odb 2 X
  801.  
  802. X = -3.14                              ; Assignment of a negative numeric
  803. If X <> '-3.14'      Odb 3 X
  804.  
  805. X = +3.14                              ; Superfluous plus sign
  806. If X <> '3.14'       Odb 4 X
  807.  
  808. X = .14                                ; Plain decimal numeric
  809. If X <> '.14'        Odb 5 X
  810.  
  811. X = 'AB' 'CD'                          ; Ordinary concatenation
  812. If X <> 'ABCD'       Odb 6 X
  813.  
  814. X = 'Pi=' 3.14                         ; Mixed concatenation
  815. If X <> 'Pi=3.14'    Odb 7 X
  816.  
  817. X = Cols 'ABCD' 2 3                    ; Set from a function
  818. If X <> 'BC'         Odb 8 X
  819.  
  820. If PT = 'N' OutNull                    ; End of this test
  821.  
  822. ;===============================================================================
  823. ; The FindPosn Command
  824. ;===============================================================================
  825.  
  826. If PT = 'N' Output '| FindPosn      |'
  827. X = 'ABBCD'                            ; Used for all tests
  828.  
  829. Z = FindPosn X 'B'                     ; Plain find
  830. If Z <> 2           Odb 1 Z
  831.  
  832. Z = FindPosn X '1*B'                   ; First occurrence
  833. If Z <> 2           Odb 2 Z
  834.  
  835. Z = FindPosn X '2*B'                   ; Second occurrence
  836. If Z <> 3           Odb 3 Z
  837.  
  838. Z = FindPosn X '>*B'                   ; Last occurrence
  839. If Z <> 3           Odb 4 Z
  840.  
  841. Z = FindPosn X 'BB' 'Include'          ; Explicit Include (it's the default)
  842. If Z <> 2           Odb 5 Z
  843.  
  844. Z = FindPosn X 'BB' 'Exclude'          ; Exclude (char position after decap)
  845. If Z <> 4           Odb 6 Z
  846.  
  847. Z = FindPosn X '-1'                    ; Char position of last character
  848. If Z <> 5           Odb 7 Z
  849.  
  850. Z = FindPosn X '-2'                    ; Second-to-last character
  851. If Z <> 4           Odb 8 Z
  852.  
  853. Z = FindPosn X '-2'                    ; Second-to-last character
  854. If Z <> 4           Odb 9 Z
  855.  
  856. Z = FindPosn X 'Z'                     ; Not found due to absence
  857. If Z <> 0           Odb 'A' Z
  858.  
  859. Z = FindPosn X 'b'                     ; Not found due to case
  860. If Z <> 0           Odb 'B' Z
  861.  
  862. Z = FindPosn X 'b' 'IgnoreCase'        ; Ignoring case
  863. If Z <> 2           Odb 'C' Z
  864.  
  865. Z = FindPosn X[3 4] 'C'                ; Searching a substring
  866. If Z <> 2           Odb 'D' Z
  867.  
  868. If PT = 'N' OutNull                    ; End of this test
  869.  
  870. ;===============================================================================
  871. ; The If Command (Literal)
  872. ;===============================================================================
  873.  
  874. If PT = 'N' Output '| If Literal    |'
  875.  
  876. X = 'ABCD'
  877. Z = 'ABCDEFG'
  878. If X = ''            Odb 1
  879. If X <> 'ABCD'       Odb 2
  880. If X >  'ABCD'       Odb 3
  881. If X <  'ABCD'       Odb 4
  882. If X Len<> 4         Odb 5
  883. If X Len>  4         Odb 6
  884. If X Len<  4         Odb 7
  885. If X ~ 'A'           Odb 8
  886. If X ~ 'a'           Odb 9             ; Not case-sensitive
  887. If X Longer  Z       Odb 'A'
  888. If Z Shorter X       Odb 'B'
  889. If X SameLen Z       Odb 'C'
  890. If X Shorter ''      Odb 'D'
  891. If '' Longer X       Odb 'E'
  892. If X Longer 1234     Odb 'F'
  893. If X SameLen 123     Odb 'G'
  894. If X[2] <> 'B'       Odb 'H'
  895. If 'C'  <> X[3]      Odb 'I'
  896. If X[2 3] <> 'BC'    Odb 'J'
  897.  
  898. If PT = 'N' OutNull                    ; End of this test
  899.  
  900. ;===============================================================================
  901. ; The If Command (Numeric)
  902. ;===============================================================================
  903.  
  904. If PT = 'N' Output '| If Numeric    |'
  905.  
  906. X = '123'
  907. Z = '123.45'
  908. If X #< '123'       Odb 1
  909. If X #> '123'       Odb 2
  910. If X #<> '123'      Odb 3
  911. If X #<> '123.0'    Odb 4
  912. If X #= Z           Odb 5
  913. If X #>= Z          Odb 6
  914. If Z #<= X          Odb 7
  915. If 124 <> X+        Odb 8
  916. If X- #<> 122       Odb 9
  917. If X[2]  #<> 2      Odb 'A'
  918. If 23 #<> X[2 3]    Odb 'B'
  919.  
  920. If PT = 'N' OutNull                    ; End of this test
  921.  
  922. ;===============================================================================
  923. ; The If Command (Length)
  924. ;===============================================================================
  925.  
  926. If PT = 'N' Output '| If Length     |'
  927.  
  928. X = 'ABC'
  929. If X Len=  0         Odb 1
  930. If X Len<> 3         Odb 2
  931. If X Len>  3         Odb 3
  932. If X Len>= 4         Odb 5
  933. If X Len<  3         Odb 6
  934. If X Len<= 2         Odb 7
  935. If X[1] Len<> 1      Odb 8
  936. If X[1 2] Len<> 2    Odb 9
  937.  
  938. If PT = 'N' OutNull                    ; End of this test
  939.  
  940. ;===============================================================================
  941. ; The If Command (Pattern)
  942. ;===============================================================================
  943.  
  944. If PT = 'N' Output '| If Pattern    |'
  945.  
  946. Pattern = 'b[aiu]t'
  947. X = '?'
  948. If 'bat'  Matches Pattern X = 'A'       ; This will match
  949. If X <> 'A' Odb 'A' X
  950. If 'bit'  Matches Pattern X = 'B'       ; This will match
  951. If X <> 'B' Odb 'B' X
  952. If 'BUT'  Matches Pattern X = 'C'       ; This will match (case is ignored)
  953. If X <> 'C' Odb 'C' X
  954. X = 'D'
  955. If 'bet'  Matches Pattern X = ''        ; This will not match
  956. If X <> 'D' Odb 'D'
  957. X = 'E'
  958. If 'boot' Matches Pattern X = ''        ; This will not match
  959. If X <> 'E' Odb 'E'
  960.  
  961. Pattern = '-*[0-9][0-9]*'              ; Pattern matches integer numbers
  962. If '1234' Matches Pattern X = 'F'      ; This will match
  963. If X <> 'F' Odb 'F' X
  964. If '1'    Matches Pattern X = 'G'      ; This will match
  965. If X <> 'G' Odb 'G' X
  966. If '-999' Matches Pattern X = 'H'      ; This will match
  967. If X <> 'H' Odb 'H' X
  968. X = 'I'
  969. If '3.14' Matches Pattern X = ''       ; No match due to decimal point
  970. If X <>  'I' Odb 'I' X
  971. X = 'J'
  972. If '-'    Matches Pattern X = ''       ; No match due to no digits
  973. If X <>  'J' Odb 'J' X
  974. X = 'K'
  975. If ''     Matches Pattern X = ''       ; No match -- it's null
  976. If X <>  'K' Odb 'K' X
  977. X = 'L'
  978. If ' 12 ' Matches Pattern X = ''       ; No match due to spaces
  979. If X <>  'L' Odb 'L' X
  980.  
  981. Pattern = '.Y.'
  982. X = '?'
  983. If 'XYZ'  Matches Pattern X = 'M'      ; Pattern will match
  984. If X <> 'M'  Odb 'M' X
  985. X = '?'
  986. If 'WXYZ' Matches Pattern X = 'N'      ; Will not match: length differs
  987. If X <> '?'  Odb 'N' X
  988. X = '?'
  989. If 'WXYZ' Comprises Pattern X = 'O'    ; This will match (substrings found)
  990. If X <> 'O'  Odb 'O' X
  991. X = '?'
  992. If 'ZYXW' Comprises Pattern X = 'P'    ; This will match (substrings found)
  993. If X <> 'P'  Odb 'P' X
  994. X = '?'
  995. If 'XYZ'  Comprises Pattern X = 'Q'    ; This will also match
  996. If X <> 'Q'  Odb 'Q' X
  997. X = '?'
  998. If 'ayc'  Comprises Pattern X = 'R'    ; Case is not important
  999. If X <> 'R'  Odb 'Q' X
  1000.  
  1001. ;-------------------------------------------------------------------------------
  1002. ; The next two demonstrations use the dynamic comparator ($Compare). This is
  1003. ; not frequently used, but is handy if you want to create a script that can,
  1004. ; for example, process queries loaded from a file (using SetFromFile).
  1005. ;-------------------------------------------------------------------------------
  1006.  
  1007. $Compare = '#>'
  1008. If 3 $Compare 4 Odb 'X'
  1009.  
  1010. $Compare = 'Matches'
  1011. If '$39.95' $Compare '\$[0-9][0-9]*\.[0-9][0-9]' X = 'Y'
  1012. If X <> 'Y'    Odb 'Y' X
  1013.  
  1014. If PT = 'N' OutNull                    ; End of this test
  1015.  
  1016. ;===============================================================================
  1017. ; The Inc Command
  1018. ;===============================================================================
  1019.  
  1020. If PT = 'N' Output '| Inc           |'
  1021.  
  1022. X = 0
  1023. Inc X                           ; Plain increment
  1024. If X <> 1 Odb 'A' X
  1025. Inc X 3                         ; Increment by 3
  1026. If X <> 4 Odb 'B' X
  1027. Inc X -5                        ; Negative increment (equivalent to Dec X 5)
  1028. If X <> -1 Odb 'C' X
  1029.  
  1030. ;-------------------------------------------------------------------------------
  1031. ; The following would not work because Inc handles only integer values.
  1032. ;-------------------------------------------------------------------------------
  1033. ; X = 1.3
  1034. ; Inc X
  1035.  
  1036. If PT = 'N' OutNull             ; End of this test
  1037.  
  1038. ;===============================================================================
  1039. ; The Insert Command
  1040. ;===============================================================================
  1041.  
  1042. If PT = 'N' Output '| Insert        |'
  1043.  
  1044. X = 'abcd'
  1045. Insert X 'c' 'Z'                       ; Insert one character at decap
  1046. If X <> 'abZcd'       Odb 1 X
  1047.  
  1048. X = 'abcd'
  1049. Insert X 'b' 'Z' 'Exclude'             ; Insert one character after
  1050. If X <> 'abZcd'       Odb 2 X
  1051.  
  1052. X = 'abcd'
  1053. Insert X 'c' 'ZZ'                      ; Insert multiple characters at decap
  1054. If X <> 'abZZcd'      Odb 3 X
  1055.  
  1056. X = 'abcd'
  1057. Insert X 'c' 'ZZ' 'Exclude'            ; Insert multiple characters after
  1058. If X <> 'abcZZd'      Odb 4 X
  1059.  
  1060. X = 'abcccd'
  1061. Insert X '2*c' 'Z'                    ; Insert at occurrence count
  1062. If X <> 'abcZccd'     Odb 5 X
  1063.  
  1064. X = 'abcd'
  1065. Insert X '' 'Z'                        ; Insert at front (same as an append)
  1066. If X <> 'Zabcd'       Odb 6 X
  1067.  
  1068. X = 'abcccd'
  1069. Insert X '2*c' 'Z' 'Exclude'          ; Insert after occurrence count
  1070. If X <> 'abccZcd'     Odb 7 X
  1071.  
  1072. X = 'abcd'
  1073. Insert X '2' 'Z'                      ; Insert positional
  1074. If X <> 'aZbcd'       Odb 8 X
  1075.  
  1076. X = 'abcd'
  1077. Insert X '-2' 'ZZ'                     ; Insert at second-to-last char
  1078. If X <> 'abZZcd'      Odb 9 X
  1079.  
  1080. X = 'abcd'
  1081. Insert X '-1' 'ZZ'                     ; Insert at last char
  1082. If X <> 'abcZZd'      Odb 'A' X
  1083.  
  1084. X = 'abcd'
  1085. Insert X 'C' 'Z'                       ; Failed search due to case
  1086. If X <> 'abcd'        Odb 'B' X
  1087.  
  1088. X = 'abcd'
  1089. Insert X 'C' 'Z' 'IgnoreCase'          ; Adjusted for case
  1090. If X <> 'abZcd'       Odb 'C' X
  1091.  
  1092. X = 'abcd'
  1093. Insert X 'C' 'Z' 'Exclude IgnoreCase'  ; Adjusted for case; insert after
  1094. If X <> 'abcZd'       Odb 'D' X
  1095.  
  1096. X = ''
  1097. Insert X 'C' 'Z'                       ; Failed search due to null source
  1098. If X <> ''            Odb 'E' X
  1099.  
  1100. X = ''
  1101. Insert X '' 'Z'                        ; Adjusted with null decap
  1102. If X <> 'Z'           Odb 'F' X
  1103.  
  1104. If PT = 'N' OutNull                    ; End of this test
  1105.  
  1106. ;===============================================================================
  1107. ; The KeepChar Command
  1108. ;===============================================================================
  1109.  
  1110. If PT = 'N' Output '| KeepChar      |'
  1111.  
  1112. X = 'ABC-123-abc-A'
  1113. KeepChar X '/A'                        ; Keep single char
  1114. If X <> 'AA'         Odb 1 X
  1115.  
  1116. X = 'ABC-123-abc-A'
  1117. KeepChar X '/AZ'                       ; Keep range of chars
  1118. If X <> 'ABCA'       Odb 2 X
  1119.  
  1120. X = 'ABC-123-abc-A'
  1121. KeepChar X '/AZ/-'                     ; Keep range and single char
  1122. If X <> 'ABC---A'    Odb 3 X
  1123.  
  1124. X = 'ABC-123-abc-A'
  1125. KeepChar X '/AZ/09'                    ; Keep two ranges
  1126. If X <> 'ABC123A'    Odb 4 X
  1127.  
  1128. X = 'ABC-123-abc-A'
  1129. KeepChar X '///AZ///09///'             ; As before, with superfluous delims
  1130. If X <> 'ABC123A'    Odb 5 X
  1131.  
  1132. X = 'ABC-123-abc-A'
  1133. KeepChar X '***AZ***09***'             ; As before, with different delims
  1134. If X <> 'ABC123A'    Odb 6 X
  1135.  
  1136. X = 'A-1-a-A'
  1137. KeepChar X '/AZ/az/-'                  ; Keep letters and dashes
  1138. If X <> 'A--a-A'     Odb 7 X
  1139.  
  1140. X = 'A-1-a-A'
  1141. KeepChar X '/ZA/za/-'                  ; Mix up the order of ranges
  1142. If X <> 'A--a-A'     Odb 8 X
  1143.  
  1144. X = 'Give me $199.00, please!'         ; Keep cash values only
  1145. KeepChar X '/$/./09'
  1146. If X <> '$199.00'    Odb 9 X
  1147.  
  1148. If PT = 'N' OutNull                    ; End of this test
  1149.  
  1150. ;===============================================================================
  1151. ; The Len Command
  1152. ;===============================================================================
  1153.  
  1154. If PT = 'N' Output '| Len           |'
  1155.  
  1156. X = 'ABCD'
  1157. Z = Len X
  1158. If Z <> 4           Odb 1 Z            ; Simple measurement
  1159.  
  1160. X = ''
  1161. Z = Len X
  1162. If Z <> 0           Odb 2 Z            ; A null is 0 characters long
  1163.  
  1164. X = ''
  1165. Y = 'DEF'
  1166. Z = Len X 'ABC' X Y 'GHI' X            ; Measuring concatenated values
  1167. If Z <> 9           Odb 3
  1168.  
  1169. If PT = 'N' OutNull                    ; End of this test
  1170.  
  1171. ;===============================================================================
  1172. ; Literals
  1173. ;===============================================================================
  1174.  
  1175. If PT = 'N' OutEnd '| Literals      |'
  1176.  
  1177. X = $78$79$7A
  1178. If X <> 'xyz'               Odb 1 X
  1179.  
  1180. X = #097#098#099
  1181. If X <> 'abc'               Odb 2 X
  1182.  
  1183. X = $20#32'Lit'#101#114'a'$6c's '
  1184. If X <> '  Literals '       Odb 3 X
  1185.  
  1186. X = #32'Lit'$65$72'als '
  1187. If X <> ' Literals '        Odb 4 X
  1188.  
  1189. X = 'Literal' $0A  $0D                 ; Both of these: 'Literal' followed
  1190. Y = 'Literal' #010 #013                ; by Carriage Return and Linefeed
  1191. If X <> Y                   Odb 5 X
  1192.  
  1193. X = 'Literal'$A#13                     ; Both of these: 'Literal' followed
  1194. Y = 'Literal'#10$D                     ; by Carriage Return and Linefeed
  1195. If X <> Y                   Odb 6 X
  1196.  
  1197. X = Len $0D$0A #10#13                  ; Encoded literals with a function
  1198. If X <> 4                   Odb 7 X
  1199.  
  1200. X = $Success                           ; Note that $ doesn't always mean hex
  1201. If 'YN' ~ X                 Odb 8 X
  1202.  
  1203. ;-------------------------------------------------------------------------------
  1204. ; The following is a nearly incomprehensible mess and is not typical of the
  1205. ; way you normally define a literal in a script. However, it does work.
  1206. ;-------------------------------------------------------------------------------
  1207. Vertibar = '|'                         ; Carriage Return and Linefeed
  1208. X = Vertibar $20'Lit'#101#114'a'$6c's'#032#32$20'   ' Vertibar
  1209. If X <> '| Literals      |' Odb 9 X
  1210.  
  1211. ;-------------------------------------------------------------------------------
  1212. ; The following lines, if uncommented, will evoke an error message.
  1213. ;-------------------------------------------------------------------------------
  1214. ; X = $$0A$0D                          ; Doubled-up $
  1215. ; X = ##10#13                          ; Doubled-up #
  1216. ; X = $0A$0D$                          ; Spurious $ at end of line
  1217. ; X = #10#13#                          ; Spurious # at end of line
  1218. ; X = $0A0D                            ; Missing $ before the $0D
  1219. ; X = $0A$0P                           ; $0P is not proper hex
  1220. ; X = #256                             ; 256 exceeds range of 0 to 255
  1221.  
  1222. ;===============================================================================
  1223. ; The LookupFile and Lookup Commands
  1224. ;===============================================================================
  1225.  
  1226. If PT = 'N' OutEnd '| LookupFile    |'
  1227.  
  1228. LookupFile 'OneTwo' 'LufSample01.txt'       ; Key Field 1; Data Field 2
  1229. LookupFile '1 & 3'  'LufSample01.txt' 1 3   ; Key Field 1; Data Field 3
  1230. LookupFile '3 & 2'  'LufSample01.txt' 3 2   ; Key Field 3; Data Field 2
  1231.  
  1232. LookupFile 'OneTwo' 'LufSample01.txt' 3 4   ; Ignored: 'OneTwo' already exists
  1233.  
  1234. If PT = 'N' Output '| Lookup        |'
  1235.  
  1236. X = Lookup 'CAT' 'OneTwo'                   ; Look up 'CAT'
  1237. If $Success <> 'Y'        Odb 1
  1238. If X <> 'Kitty'           Odb 2 X
  1239.  
  1240. X = Lookup 'Car' 'OneTwo'                   ; This will fail due to case
  1241. If $Success <> 'N'        Odb 3             ; The file has 'CAR', not 'Car'
  1242.  
  1243. X = Lookup 'Car' 'OneTwo' 'IgnoreCase'      ; Case problem fixed
  1244. If $Success <> 'Y'        Odb 4
  1245. If X <> 'Vehicle'         Odb 5 X
  1246.  
  1247. X = Lookup 'ThisIsField1' '1 & 3'           ; Key Field 1; Data Field 3
  1248. If $Success <> 'Y'        Odb 6
  1249. If X <> 'ThisIsField3'    Odb 7 X
  1250.  
  1251. X = Lookup 'ThisIsField3' '3 & 2'           ; Key Field 3; Data Field 2
  1252. If $Success <> 'Y'        Odb 6
  1253. If X <> 'ThisIsField2'    Odb 8 X
  1254.  
  1255. Z = 'OneTwo'                                ; Save a bit of typing
  1256. X = Lookup 666 Z                            ; Key Field 1; Data Field 2
  1257. If $Success = 'N'         Odb 9
  1258. If X <> $35$35$35         Odb 'A' X         ; $35$35$35 = '555'
  1259.  
  1260. X = Lookup 333 Z                            ; Key Field 1; Data Field 2
  1261. If $Success = 'N'         Odb 'B'
  1262. If X <> 222               Odb 'C' X
  1263.  
  1264. If PT = 'N' OutNull                         ; End of this test
  1265.  
  1266. ;===============================================================================
  1267. ; The MassChange Command
  1268. ;===============================================================================
  1269.  
  1270. If PT = 'N' Output '| MassChange    |'
  1271.  
  1272. LookupFile 'TwoOne' 'LufSample01.txt' 2 1   ; Key Field 2; Data Field 1
  1273.  
  1274. X = 'CAR CAT'
  1275. MassChange X 'OneTwo'                       ; Translating one way
  1276. If X <> 'Vehicle Kitty' Odb '1A' X
  1277. MassChange X 'TwoOne'                       ; Translating back to original
  1278. If X <> 'CAR CAT'       Odb '1B' X
  1279.  
  1280. X = 'CAR Cat'
  1281. MassChange X 'OneTwo'                       ; Note that default is 'MatchCase'
  1282. If X <> 'Vehicle Cat'   Odb '2A' X          ; Thus, 'Cat' isn't changed
  1283. X = 'Car Cat'
  1284. MassChange X 'OneTwo' 'IgnoreCase'          ; This time we use 'IgnoreCase'
  1285. If X <> 'Vehicle Kitty' Odb '2B' X
  1286.  
  1287. X = 'abcd'
  1288. MassChange X 'OneTwo'                       ; Character remapping (this Lookup
  1289. If X <> 'ABCd'          Odb '3' X           ; table only defines 'a', 'b', 'c')
  1290.  
  1291. X = 'A B C'
  1292. MassChange X '1 & 3' 'IgnoreCase'           ; Phonetic character remapping
  1293. If X <> 'Ay Bee See'    Odb '4' X
  1294.  
  1295. If PT = 'N' OutNull                         ; End of this test
  1296.  
  1297. ;===============================================================================
  1298. ; The Numeric Command
  1299. ;===============================================================================
  1300.  
  1301. If PT = 'N' Output '| Numeric       |'
  1302.  
  1303. Z = 123
  1304. X = Numeric Z                          ; '123' is indeed numeric
  1305. If X <> 'Y'     Odb 'A' X
  1306.  
  1307. Z = 'Woof'
  1308. X = Numeric Z                          ; That wasn't numeric
  1309. If X <> 'N'     Odb 'B1' X
  1310.  
  1311. Z = ''
  1312. X = Numeric Z                          ; Nulls aren't considered numeric
  1313. If X <> 'N'     Odb 'B2' X
  1314.  
  1315. Z = '-'
  1316. X = Numeric Z                          ; A minus sign isn't a numeric
  1317. If X <> 'N'     Odb 'B3' X
  1318.  
  1319. Z = '12A34'                            ; Note the embedded letter
  1320. X = Numeric Z                          ; So this isn't numeric
  1321. If X <> 'N'     Odb 'B4' X
  1322.  
  1323. Z = 'A1234'                            ; Note the letter in front
  1324. X = Numeric Z                          ; So this isn't numeric
  1325. If X <> 'N'     Odb 'B5' X
  1326.  
  1327. Z = '1234A'                            ; Note the letter at the end
  1328. X = Numeric Z                          ; So this isn't numeric
  1329. If X <> 'N'     Odb 'B6' X
  1330.  
  1331. Z = 3.14159
  1332. X = Numeric Z                          ; By default, we only accept integers
  1333. If X <> 'N'     Odb 'C' X
  1334.  
  1335. Z = '3.14159'
  1336. X = Numeric Z 'Yes'                    ; Now will we accept real numbers
  1337. If X <> 'Y'     Odb 'D1' X
  1338.  
  1339. Z = '3.14.159'                         ; Note the extra decimal point
  1340. X = Numeric Z 'Yes'                    ; So this won't be numeric
  1341. If X <> 'N'     Odb 'D2' X
  1342.  
  1343. Z = '-9999'
  1344. X = Numeric Z 'No'                     ; Negative numbers are numeric
  1345. If X <> 'Y'     Odb 'E1' X
  1346.  
  1347. Z = '- 9999'                           ; Note the embedded space
  1348. X = Numeric Z 'No'                     ; So this isn't numeric
  1349. If X <> 'N'     Odb 'E2' X
  1350.  
  1351. Z = '+99.99'
  1352. X = Numeric Z 'Yes'                    ; A leading + sign is ignored
  1353. If X <> 'Y'     Odb 'F' X
  1354.  
  1355. If PT = 'N' OutNull
  1356.  
  1357. ;===============================================================================
  1358. ; The OutCSV Command
  1359. ;===============================================================================
  1360. ;
  1361. ;   The following is included for completeness but is not a good demonstration
  1362. ;   of the powerful OutCSV command.  For a better demonstration, please see the
  1363. ;   ScrOutCSVDemo script.
  1364. ;
  1365. ;-------------------------------------------------------------------------------
  1366.  
  1367. OutCSV 'QuoteChar |' 'Control'
  1368. OutCSV 'MinWidth 17' 'Control'
  1369. OutCSV 'MaxWidth 17' 'Control'
  1370. OutCSV ' ' 'Init'
  1371. OutCSV ' OutCSV Max' 'Quoted'
  1372. OutCSV '' 'Done'
  1373.  
  1374. OutCSV ' ' 'Init'
  1375. OutCSV ' OutCSV Min         ' 'Quoted'
  1376. OutCSV '' 'Done'
  1377.  
  1378. ;===============================================================================
  1379. ; The Odb Command                | Yes, this looks a bit ugly, as headers go,  |
  1380. ; The Output Command             | but people who are consulting this file for |
  1381. ; The OutNull Command            | examples will probably search for a string  |
  1382. ; The OutEnd Command             | in the form "The [X] Command".              |
  1383. ;===============================================================================
  1384.  
  1385. If PT = 'N' Odb ' Odb           '
  1386. X = 'Out'
  1387. Y = 'put'
  1388. If PT = 'N' Output '| ' X Y '        |'   ; Concatenated values
  1389. If PT = 'N' OutNull                       ; Move to next line
  1390. If PT = 'N' Output '| OutNull       |'    ; Included here for completeness
  1391. If PT = 'N' OutNull                       ; Move to next line
  1392. Z = 'OutEnd'
  1393. If PT = 'N' OutEnd '| ' Z '        |'     ; Concatenated values
  1394.  
  1395. ;===============================================================================
  1396. ; The Otherwise Command
  1397. ;===============================================================================
  1398.  
  1399. If PT = 'N' OutEnd '| Otherwise     |'
  1400.  
  1401. X = 3
  1402. If X = 4 Odb 'A' X                     ; This is false, so it will not happen
  1403. Otherwise X = 999                      ; Since it was false, this WILL happen
  1404. If X <> 999 Odb 'B' X
  1405.  
  1406. Cntr = 3
  1407. If Cntr = 3 Call AddCntr               ; This is true, so it will happen
  1408. Otherwise Cntr = 999                   ; This will NOT happen
  1409. If Cntr <> 4 Odb 'C' Cntr
  1410.  
  1411. Cntr = 777
  1412. If Cntr = 3 Call AddCntr               ; This is false, so it will not happen
  1413. Otherwise Cntr = 888                   ; Thus, this WILL happen
  1414. If Cntr <> 888 Odb 'D' Cntr
  1415.  
  1416. Cntr = 3
  1417. If Cntr = 3 Call AddCntr               ; This is true, so it will happen
  1418. Otherwise   Call AddCntr2              ; Thus, this will NOT happen
  1419. If Cntr <> 4 Odb 'E' Cntr
  1420.  
  1421. Cntr = 4
  1422. If Cntr = 3 Call AddCntr               ; This is false, so it will not happen
  1423. Otherwise   Call AddCntr2              ; Thus, this WILL happen
  1424. If Cntr <> 6 Odb 'F' Cntr
  1425.  
  1426. ;-------------------------------------------------------------------------------
  1427. ; The next lines demonstrate that comments and null lines aren't counted when
  1428. ; applying the rule that an Otherwise must immediately follow an If command.
  1429. ;-------------------------------------------------------------------------------
  1430. Cntr = 4
  1431. If Cntr = 3 Call AddCntr               ; This is false, so it will not happen
  1432.  
  1433. ;
  1434. ;   Visit www.tc123.com if you'd like to see the personal home page
  1435. ;   of the lead programmer at Pinnacle Software.
  1436. ;
  1437.  
  1438. Otherwise   Call AddCntr2              ; Thus, this WILL happen
  1439. If Cntr <> 6 Odb 'F' Cntr
  1440.  
  1441. ;-------------------------------------------------------------------------------
  1442. ; If the next lines are uncommented it will cause an error, since an Otherwise
  1443. ; command must appear on a line immediately following an If command (comments
  1444. ; and null lines don't count, of course).
  1445. ;-------------------------------------------------------------------------------
  1446. ; X = 3
  1447. ; Otherwise OutEnd 'Stand-alone Otherwise'
  1448.  
  1449. ;===============================================================================
  1450. ; The OutRuler Command (actual command commented out to keep output tidy)
  1451. ;===============================================================================
  1452.  
  1453. X =  '| OutRuler      |'
  1454. If PT = 'N' OutEnd X
  1455. ; OutRuler X
  1456.  
  1457. ;===============================================================================
  1458. ; The Overlay Command
  1459. ;===============================================================================
  1460.  
  1461. If PT = 'N' Output '| Overlay       |'
  1462.  
  1463. X = 'abcd'
  1464. Overlay X '3' 'Z'                      ; Positional overlay
  1465. If X <> 'abZd'        Odb 1 X
  1466. If $Success = 'N'     Odb 2
  1467.  
  1468. X = 'abcd'
  1469. Overlay X '<*b' 'ZZ'                   ; Overlay first occurrence
  1470. If X <> 'aZZd'        Odb 3 X
  1471. If $Success <> 'Y'    Odb 4
  1472.  
  1473. X = 'abcd'
  1474. Overlay X '<*b' 'ZZ' 'Exclude'         ; Exclude found text
  1475. If X <> 'abZZ'        Odb 5 X
  1476. If $Success Is 'n'    Odb 6
  1477.  
  1478. X = 'abcd'
  1479. Overlay X 'w' 'ZZ'                     ; Failed search
  1480. If X <> 'abcd'        Odb 7 X
  1481. If $Success Is 'y'    Odb 8
  1482.  
  1483. X = 'abbb'
  1484. Overlay X '2*b' 'ZZ'                   ; Overlay second occurrence
  1485. If X <> 'abZZ'        Odb 9 X
  1486.  
  1487. X = 'abbb'
  1488. Overlay X '>*b' 'Z'                    ; Overlay last occurrence
  1489. If X <> 'abbZ'        Odb 'A' X
  1490.  
  1491. X = 'abbb'
  1492. Overlay X '2*b' 'ZZ' 'Exclude'         ; As above, but exclude found text
  1493. If X <> 'abbZZ'       Odb 'B' X
  1494.  
  1495. X = 'abcd'
  1496. Overlay X '' 'ZZ'                      ; Overlay from beginning
  1497. If X <> 'ZZcd'        Odb 'C' X
  1498.  
  1499. X = 'abcd'
  1500. Overlay X 'd' 'ZZZ'                    ; Extend length of variable
  1501. If X <> 'abcZZZ'      Odb 'D' X
  1502.  
  1503. X = 'abcd'
  1504. Overlay X 'B' 'ZZ'                     ; Failed due to case
  1505. If X <> 'abcd'        Odb 'E' X
  1506.  
  1507. X = 'abcd'
  1508. Overlay X 'B' 'ZZ' 'IgnoreCase'        ; Adjusted for case
  1509. If X <> 'aZZd'        Odb 'F' X
  1510.  
  1511. If PT = 'N' OutNull                    ; End of this test
  1512.  
  1513. ;===============================================================================
  1514. ; The Padded Command
  1515. ;===============================================================================
  1516.  
  1517. If PT = 'N' Output '| Padded        |'
  1518.  
  1519. X = Padded 'AB' 4                      ; Defaults are 'Right' and ' '
  1520. If X <> 'AB  '    then    Odb 1 X      ; Use of "then" is non-standard
  1521.  
  1522. X = Padded 'CD' 5 'Left'
  1523. If X <> '   CD'   then    Odb 2 X
  1524.  
  1525. X = Padded 'EF' 6 'Center'
  1526. If X <> '  EF  '  then    Odb 3 X
  1527.  
  1528. X = Padded 'XYZ' 7 'Left' 'x'
  1529. If X <> 'xxxxXYZ' then    Odb 4 X
  1530.  
  1531. X = ''
  1532. X = Padded X '3' 'Left' 'x'
  1533. If X <> 'xxx'     then    Odb 5 X
  1534.  
  1535. If PT = 'N' OutNull                    ; End of this test
  1536.  
  1537. ;===============================================================================
  1538. ; The Parse Command
  1539. ;===============================================================================
  1540.  
  1541. If PT = 'N' Output '| Parse         |'
  1542.  
  1543. Z = 'ABCD'
  1544. X = Parse Z 'B' 'D'                    ; Plain decapsulators
  1545. If X <> 'c'               Odb 1 X      ; If comparisons are case-insensitive
  1546.  
  1547. Z = 'ABBCCDD'
  1548. X = Parse Z '2*B' '2*D'                ; Second occurrence, "From" and "To"
  1549. If X <> 'CCD'             Odb 2 X
  1550.  
  1551. Z = 'ABBCCDD'
  1552. X = Parse Z '2*B' '2*D' 'Include'      ; As above, but Included
  1553. If X <> 'BCCDD'           Odb 3 X
  1554.  
  1555. Z = 'ABBCCDD'
  1556. X = Parse Z '<*b' '>*d' 'IgnoreCase'   ; First and last, case ignored
  1557. If X <> 'BCCD'            Odb 4 X
  1558.  
  1559. Z = 'ABCD'
  1560. X = Parse Z '-3' '-2'                  ; Counting from the right
  1561. If X <> 'BC'              Odb 5 X
  1562.  
  1563. Z = 'ABCD'
  1564. X = Parse Z '-3' ''                    ; Null "To" decapsulator
  1565. If X <> 'BCD'             Odb 6 X
  1566.  
  1567. Z = 'ABCD'
  1568. X = Parse Z '' '-2'                    ; Null "From" decapsulator
  1569. If X <> 'ABC'             Odb 7 X
  1570.  
  1571. Z = 'ABCD'
  1572. X = Parse Z '' '-2'                    ; Null "From" decapsulator
  1573. If X <> 'ABC'             Odb 8 X
  1574.  
  1575. Z = 'ABCD'
  1576. X = Parse Z '' ''                      ; Both decapsulators null
  1577. If X <> 'ABCD'            Odb 9 X
  1578.  
  1579. Z = 'John,Aloysius,Smith'
  1580. Name1 = Parse Z '' ',' 'Cut'
  1581. Name2 = Parse Z '' ',' 'Cut'
  1582. Name3 = Parse Z '' ',' 'Cut'           ; This should fail
  1583. Name4 = Parse Z '' ',' 'Cut Relaxed'   ; This should work
  1584. If Name1 <> 'John'        Odb 'A' X
  1585. If Name2 <> 'Aloysius'    Odb 'B' X
  1586. If Name3 <> ''            Odb 'C' X
  1587. If Name4 <> 'Smith'       Odb 'D' X
  1588.  
  1589. Z = 'ABCD'
  1590. X = Parse Z 'b' 'D'                    ; Fail due to case
  1591. If X <> ''                Odb 'E' X
  1592.  
  1593. Z = 'ABCD'
  1594. X = Parse Z 'b' 'D' 'IgnoreCase'       ; Adjust for case
  1595. If X <> 'C'               Odb 'F' X
  1596.  
  1597. Z = 'AB12AB34AB56AB78'
  1598. X = Parse Z 'B' '@*B'                  ; From first 'B' to following 'B'
  1599. If X <> '12A'             Odb 'G1' X
  1600.  
  1601. X = Parse Z '2*B' '@*B'                ; From second 'B' to following 'B'
  1602. If X <> '34A'             Odb 'G2' X
  1603.  
  1604. X = Parse Z '3*B' '@*AB'               ; From third 'B' to following 'AB'
  1605. If X <> '56'              Odb 'G3' X
  1606.  
  1607. Z = 'AB,CD,EF'
  1608. X = Parse Z '' '@*,'                   ; From start, to following comma
  1609. If X <> 'AB'              Odb 'G4' X
  1610.  
  1611. Z = ',CD,EF'                           ; Note that first field is null
  1612. X = Parse Z '' '@*,'                   ; From start, to following comma
  1613. If X <> ''                Odb 'G5' X
  1614.  
  1615. Z = ',CD,EF'
  1616. X = Parse Z ',' '@*,'                  ; From first to second comma
  1617. If X <> 'CD'              Odb 'G6' X
  1618.  
  1619. If PT = 'N' OutNull                    ; End of this test
  1620.  
  1621. ;===============================================================================
  1622. ; The Plural Command
  1623. ;===============================================================================
  1624.  
  1625. If PT = 'N' Output '| Plural        |'
  1626.  
  1627. N = 1
  1628. X = Plural 'cat' N
  1629. If X <> 'cat'      Odb 'A' X
  1630.  
  1631. N = 2
  1632. X = Plural 'cat' N
  1633. If X <> 'cats'     Odb 'B' X
  1634.  
  1635. N = 0
  1636. X = Plural 'cat' N
  1637. If X <> 'cats'     Odb 'C' X
  1638.  
  1639. N = ' 1.5 '                            ; Note that spaces are ignored
  1640. X = Plural 'cat' N 'No'                ; Not preserving length (default)
  1641. If X <> 'cats'     Odb 'D' X
  1642.  
  1643. N = 1
  1644. X = Plural 'cat' N 'Yes'               ; We're preserving length
  1645. If X <> 'cat '     Odb 'E1' X
  1646.  
  1647. N = 2
  1648. X = Plural 'cat' N 'Yes'               ; We're preserving length
  1649. If X <> 'cats'     Odb 'E2' X
  1650.  
  1651. If PT = 'N' OutNull                    ; End of this test
  1652.  
  1653. ;===============================================================================
  1654. ; The ParseName Command
  1655. ;===============================================================================
  1656.  
  1657. If PT = 'N' Output '| Procedure     |'
  1658.  
  1659. Z = 'Miss Mary Jane Smith, Esq.'
  1660. ParseName Z 'No' addform first middle last suffix
  1661. If addform <> 'Miss'           Odb 'A1' addform
  1662. If first   <> 'Mary'           Odb 'A2' first
  1663. If middle  <> 'Jane'           Odb 'A3' middle
  1664. If last    <> 'Smith'          Odb 'A4' last
  1665. If suffix  <> 'Esq.'           Odb 'A5' suffix
  1666.  
  1667. Z = 'Fred Jones III'
  1668. ParseName Z 'No' addform first middle last suffix
  1669. If addform <> ''               Odb 'B1' addform
  1670. If first   <> 'Fred'           Odb 'B2' first
  1671. If middle  <> ''               Odb 'B3' middle
  1672. If last    <> 'Jones'          Odb 'B4' last
  1673. If suffix  <> 'III'            Odb 'B5' suffix
  1674.  
  1675. Z = 'Elvis "The Pelvis" Presley'
  1676. ParseName Z 'No' addform first middle last suffix
  1677. If addform <> ''               Odb 'C1' addform
  1678. If first   <> 'Elvis'          Odb 'C2' first
  1679. If middle  <> '"The Pelvis"'   Odb 'C3' middle
  1680. If last    <> 'Presley'        Odb 'C4' last
  1681. If suffix  <> ''               Odb 'C5' suffix
  1682.  
  1683. Z = 'Whizzco Inc.'
  1684. ParseName Z 'No' addform first middle last suffix    ; Company-detect disabled
  1685. If addform <> ''               Odb 'D1' addform
  1686. If first   <> 'Whizzco'        Odb 'D2' first
  1687. If middle  <> ''               Odb 'D3' middle
  1688. If last    <> 'Inc'            Odb 'D4' last
  1689. If suffix  <> ''               Odb 'D5' suffix
  1690.  
  1691. Z = 'Whizzco Inc.'
  1692. ParseName Z 'Yes' addform first middle last suffix   ; Company-detect enabled
  1693. If addform <> ''               Odb 'E1' addform
  1694. If first   <> 'Whizzco Inc.'   Odb 'E2' first
  1695. If middle  <> ''               Odb 'E3' middle
  1696. If last    <> ''               Odb 'E4' last
  1697. If suffix  <> ''               Odb 'E5' suffix
  1698.  
  1699. Z = 'Mr. Robert J. L. Van de Graff the third'
  1700. ParseName Z 'Yes' addform first middle last suffix
  1701. If addform <> 'Mr.'            Odb 'F1' addform
  1702. If first   <> 'Robert'         Odb 'F2' first
  1703. If middle  <> 'J. L.'          Odb 'F3' middle
  1704. If last    <> 'Van de Graff'   Odb 'F4' last
  1705. If suffix  <> 'the third'      Odb 'F5' suffix
  1706.  
  1707. Z = 'Aloysius Katz'
  1708. ParseName Z 'Yes' addform first middle last suffix
  1709. If addform <> ''               Odb 'G1' addform
  1710. If first   <> 'Aloysius'       Odb 'G2' first
  1711. If middle  <> ''               Odb 'G3' middle
  1712. If last    <> 'Katz'           Odb 'G4' last
  1713. If suffix  <> ''               Odb 'G5' suffix
  1714.  
  1715. If PT = 'N' OutNull                    ; End of this test
  1716.  
  1717. ;===============================================================================
  1718. ; The Procedure Command (procedures traditionally go at the end of a script)
  1719. ;===============================================================================
  1720.  
  1721. If PT = 'N' Output '| Procedure     |'
  1722.  
  1723. Procedure MyProcedure
  1724.   MyProcedure = 'Hello'                ; Set the var named after the procedure
  1725.   X           = 'Set by MyProcedure'   ; Set some other variable
  1726.   If MyProcedure <> 'Hello' >>
  1727.     Odb 'A' MyProcedure
  1728. End
  1729.  
  1730. ;Procedure MyProcedure                 ; If you uncomment these lines it will
  1731. ;  MyProcedure = 'Hello, world!'       ; cause an error, since you can only have
  1732. ;End                                   ; one procedure with a given name
  1733.  
  1734. If PT = 'N' OutNull                    ; End of this test
  1735.  
  1736. ;===============================================================================
  1737. ; The Que Command
  1738. ;===============================================================================
  1739.  
  1740. If PT = 'N' Output '| Que           |'
  1741.  
  1742. X = Que 3 = 3                          ; This is obviously true
  1743. If X <> 'Y'    Odb 'A' X
  1744.  
  1745. X = Que 3 = 4                          ; This is obviously false
  1746. If X <> 'N'    Odb 'A' X
  1747.  
  1748. X = Que 'a' = 'A'                      ; Case is ignored by default
  1749. If X <> 'Y'    Odb 'C' X
  1750.  
  1751. X = Que ' a ' = 'A'                    ; The spaces make this false
  1752. If X <> 'N'    Odb 'D' X
  1753.  
  1754. X = Que ' a ' Is 'A'                   ; Is comparator fixes the space problem
  1755. If X <> 'Y'    Odb 'E' X               ; and serves up a koan for Ayn Rand fans
  1756.  
  1757. X = Que 'a' = 'A' 'MatchCase'          ; Now case must match
  1758. If X <> 'N'    Odb 'F' X
  1759.  
  1760. X = Que 'a3' Matches '[A-Z][1-9]'      ; Case is ignored, so this is true
  1761. If X <> 'Y'    Odb 'G' X
  1762.  
  1763. X = Que 'a3' Matches '[A-Z][1-9]' >>   ; This test will be false, because we
  1764.   'MatchCase'                          ; are requesting case-sensitivity
  1765. If X <> 'N'    Odb 'H' X
  1766.  
  1767. If PT = 'N' OutNull                    ; End of this test
  1768.  
  1769. ;===============================================================================
  1770. ; The Rounding Command
  1771. ;===============================================================================
  1772.  
  1773. ;-------------------------------------------------------------------------------
  1774. ; Note: Turning Rounding off (i.e. setting it to 'No') is NOT RECOMMENDED.
  1775. ; Please see the scripting manual for an explanation.
  1776. ;-------------------------------------------------------------------------------
  1777.  
  1778. If PT = 'N' Output '| Rounding      |'
  1779.  
  1780. Rounding 'No'                          ; Turn off rounding
  1781. X = CalcReal 17.568 / 3 '2'            ; 2 decimals; actual answer is 5.856
  1782. If X[1 4] <> 5.85  Odb 1 X             ; We simply truncated the answer
  1783.  
  1784. Rounding 'Yes'                         ; Turn on rounding (default)
  1785. X = CalcReal 17.568 / 3 '2'            ; 2 decimals; actual answer is 5.856
  1786. If X <> 5.86       Odb 2 X
  1787.  
  1788. Rounding 'No'                          ; Turn rounding off again
  1789. X = CalcReal 17.568 / 3 '2'            ; 2 decimals; actual answer is 5.856
  1790. If X[1 4] <> 5.85  Odb 3 X             ; We simply truncated the answer again
  1791.  
  1792. X = CalcReal 10.009 * 9 1              ; Actual answer is 90.081
  1793. If X[1 4] <> 90.0  Odb '4A' X          ; But we're just truncating
  1794.  
  1795. Rounding 'Yes'
  1796. X = CalcReal 10.009 * 9 1              ; Actual answer is 90.081
  1797. If X <> 90.1       Odb '4B' X          ; Rounding-up gives a different answer
  1798.  
  1799. X = CalcReal 10.009 * 9 2              ; Actual answer is 90.081
  1800. If X <> 90.08      Odb '4C' X          ; Rounding-up 2 places this time
  1801.  
  1802. ;-------------------------------------------------------------------------------
  1803. ; In the next example we are using "Float". This calculation can actually
  1804. ; generate the answer 90.0810000000000128 -- which is very close to the
  1805. ; right answer, but contains some "noise". Whenever you use "Float", you
  1806. ; should be aware that when computer calculations are taken to the limit
  1807. ; of the software's precision, it can result in a miniscule inaccuracy.
  1808. ;-------------------------------------------------------------------------------
  1809. X = CalcReal 10.009 * 9 'Float'        ; Get whatever decimal places we can
  1810. If X[1 5] <> 90.08 Odb '4D' X
  1811.  
  1812. If PT = 'N' OutNull                    ; End of this test
  1813.  
  1814. ;===============================================================================
  1815. ; The ScanFollow Command
  1816. ;===============================================================================
  1817.  
  1818. If PT = 'N' Output '| ScanFollow    |'
  1819.  
  1820. ScanList = '/A/Apple/B/Badger/C/Cat/D/Dog'
  1821.  
  1822. X = ScanFollow 'A' ScanList              ; Look up 'A'
  1823. If X <> 'Apple'       Odb 'A' X
  1824.  
  1825. X = ScanFollow 'Z' ScanList              ; Look up 'Z' (not found)
  1826. If X <> ''            Odb 'B' X          ; Default "Not Found" value is null
  1827.  
  1828. X = ScanFollow 'Z' ScanList 'Moose'      ; Look up 'Z' (not found)
  1829. If X <> 'Moose'       Odb 'C' X          ; "Not Found" value returned
  1830.  
  1831. X = ScanFollow 'a' ScanList 'Pig' 'MatchCase'  ; Not found due to case
  1832. If X <> 'Pig'         Odb 'D' X                ; Returns "Not Found" value
  1833.  
  1834. X = ScanFollow 'Dog' ScanList 'Cow'      ; Nothing follows 'Dog'
  1835. If X <> 'Cow'         Odb 'E' X          ; We'll get the "Not Found" value
  1836.  
  1837. If PT = 'N' OutNull                      ; End of this test
  1838.  
  1839. ;===============================================================================
  1840. ; The ScanPosn Command
  1841. ;===============================================================================
  1842.  
  1843. If PT = 'N' Output '| ScanPosn      |'
  1844.  
  1845. Source = 'Duck Duck Goose Cat Moose'
  1846. ScanList = '/Elk/Duck/Cat'
  1847. ScanPosn p1 p2 Source ScanList         ; 'Any' scan
  1848. If $Success = 'N'      Odb 1
  1849. If p1 <> 1             Odb 'A' p1
  1850. If p2 <> 4             Odb 'B' p2
  1851.  
  1852. Source = 'Cow Scowl Cowboy'
  1853. ScanList = '/Cow'
  1854. ScanPosn p1 p2 Source ScanList 'First' ; 'First' scan
  1855. If $Success = 'N'     Odb 2
  1856. If p1 <> 1            Odb 'C' p1
  1857. If p2 <> 3            Odb 'D' p2
  1858.  
  1859. Source = 'MegaWhizco International'
  1860. ScanList = '*CO*WHIZCO*MEGAWHIZ'       ; Asterisk used as delimiter
  1861. ScanPosn p1 p2 Source ScanList 'Last'  ; 'Last' scan, with "best-match"
  1862. If $Success <> 'Y'    Odb 3
  1863. If p1 <> 5            Odb 'E' p1
  1864. If p2 <> 10           Odb 'F' p2
  1865.  
  1866. ScanPosn p1 p2 'Woof' '/Dog/Cat'       ; No string will be found
  1867. If $Success <> 'N'    Odb 4
  1868. If p1 <> 0            Odb 'G' p1
  1869. If p2 <> 0            Odb 'H' p2
  1870.  
  1871. X = 'Cow Cat Dog'
  1872. Y = '/COW/CAT/DOG'
  1873. ScanPosn p1 p2 X Y 'Last MatchCase'    ; No string found due to case
  1874. If $Success <> 'N'    Odb 5
  1875. If p1 <> 0            Odb 'I' p1
  1876. If p2 <> 0            Odb 'J' p2
  1877.  
  1878. ScanPosn p1 p2 X Y 'Last IgnoreCase'   ; Case problem explicitly solved
  1879. If $Success = 'N'     Odb 6
  1880. If p1 <> 9            Odb 'K' p1
  1881. If p2 <> 11           Odb 'L' p2
  1882.  
  1883. Source = 'MegaWhizco International'
  1884. ScanList = '\CO\WHIZCO\MEGAWHIZ'       ; Backslash used as delimiter
  1885. ScanPosn p1 p2 Source ScanList 'First' ; 'First' scan, with "best-match"
  1886. If $Success <> 'Y'    Odb 7
  1887. If p1 <> 1            Odb 'M' p1
  1888. If p2 <> 8            Odb 'N' p2
  1889.  
  1890. X = 'Kitty Cats Are Cool'
  1891. Y = '/c.t/co*l'
  1892. ScanPosn p1 p2 X Y 'First RegExp'      ; 'First' with regular expression
  1893. If $Success = 'N'     Odb 8
  1894. If p1 <> 7            Odb 'O' p1
  1895. If p2 <> 9            Odb 'P' p2
  1896.  
  1897. ScanPosn p3 p4 X Y 'Last RegExp'       ; 'Last' with regular expression
  1898. If $Success = 'N'     Odb 9
  1899. If p3 <> 16           Odb 'Q' p3
  1900. If p4 <> 19           Odb 'R' p4
  1901.  
  1902. X = '$398.00! Give me $199.00 2 times!'
  1903. Y = '@\$[0-9][0-9]*\.[0-9][0-9]'       ; Pattern for a currency value
  1904. ScanPosn p1 p2 X Y 'RegExp Last'
  1905. If $Success = 'N'     Odb 10
  1906. If p1 <> 18           Odb 'S' p1
  1907. If p2 <> 24           Odb 'T' p2
  1908. X = Cols X p1 p2                       ; Extract the currency value we found
  1909. If X <> '$199.00'     Odb 'U' X
  1910.  
  1911. If PT = 'N' OutNull                    ; End of this test
  1912.  
  1913. ;===============================================================================
  1914. ; The SetFromFile Command
  1915. ;===============================================================================
  1916.  
  1917. If PT = 'N' Output '| SetFromFile   |'
  1918.  
  1919. X = SetFromFile 'ScrExercise.txt'      ; This script file
  1920. If X[1 5] <> ';===='    Odb 1 X        ; The first comment line
  1921. If $Success <> 'Y'      Odb 2
  1922.  
  1923. X = SetFromFile 'NoSuchFile.txt'       ; Non-existent file
  1924. If X <> ''              Odb 3 X
  1925. If $Success <> 'N'      Odb 4
  1926.  
  1927. If PT = 'N' OutNull                    ; End of this test
  1928.  
  1929. ;===============================================================================
  1930. ; The SplitCSV Command
  1931. ;===============================================================================
  1932.  
  1933. If PT = 'N' Output '| SplitCSV      |'
  1934.  
  1935. A = '"Cat","Dog","Cow"'
  1936. X = SplitCSV A '/'
  1937. If X <> 'Cat/Dog/Cow' Odb 'A' X
  1938.  
  1939. A = '"Fred ""Wonderdude"" Smith";123.45;"416-555-1212"'
  1940. X = SplitCSV A '@' ';'
  1941. If X <> 'Fred "Wonderdude" Smith@123.45@416-555-1212' Odb 'B' X
  1942.  
  1943. A = '1,2,3'
  1944. X = SplitCSV A
  1945. Test = 1 #13 2 #13 3
  1946. If X <> Test Odb 'C' X
  1947.  
  1948. If PT = 'N' OutNull                    ; End of this test
  1949.  
  1950. ;===============================================================================
  1951. ; The Stop Command (included for completeness -- used at end of script)
  1952. ;===============================================================================
  1953.  
  1954. If PT = 'N' OutEnd '| Stop          |'  ; Included here for completeness
  1955.  
  1956. ;===============================================================================
  1957. ; The TrimChar Command
  1958. ;===============================================================================
  1959.  
  1960. If PT = 'N' Output '| TrimChar      |'
  1961.  
  1962. X = ' xxx///yyy zzz/// '
  1963. TrimChar X
  1964. If X <> 'xxx///yyy zzz///'  Odb 1 X
  1965.  
  1966. X = ' xxx///yyy zzz/// '
  1967. TrimChar X 'L '
  1968. If X <> 'xxx///yyy zzz/// ' Odb 2 X
  1969.  
  1970. X = ' xxx///yyy zzz/// '
  1971. TrimChar X 'R '
  1972. If X <> ' xxx///yyy zzz///' Odb 3 X
  1973.  
  1974. X = ' xxx///yyy zzz/// '
  1975. TrimChar X 'B '
  1976. If X <> 'xxx///yyy zzz///'  Odb 4 X
  1977.  
  1978. X = ' xxx///yyy zzz/// '
  1979. TrimChar X 'A '
  1980. If X <> 'xxx///yyyzzz///'   Odb 5 X
  1981.  
  1982. X = ' xxx///yyy zzz/// '
  1983. TrimChar X 'B Ay'
  1984. If X <> 'xxx/// zzz///'     Odb 6 X
  1985.  
  1986. X = ' xxx///yyy zzz/// '
  1987. TrimChar X 'A Az'
  1988. If X <> 'xxx///yyy///'      Odb 7 X
  1989.  
  1990. X = ' xxx///yyy zzz/// '
  1991. TrimChar X 'M/'
  1992. If X <> ' xxx/yyy zzz/ '    Odb 8 X
  1993.  
  1994. X = ' xxx///yyy zzz/// '
  1995. TrimChar X 'B M/'
  1996. If X <> 'xxx/yyy zzz/'      Odb 9 X
  1997.  
  1998. X = ' xxx///yyy zzz/// '
  1999. TrimChar X 'MxMyMzM/'
  2000. If X <> ' x/y z/ '          Odb 'A' X
  2001.  
  2002. X = ' xxx///yyy zzz/// '
  2003. TrimChar X 'B Lx'                      ; The Lx will not accomplish anything
  2004. If X <> 'xxx///yyy zzz///'  Odb 'B' X
  2005.  
  2006. X = ' xxx///yyy zzz/// '
  2007. TrimChar X 'B '                        ; We address the simultaneity issue
  2008. TrimChar X 'Lx'                        ; by doing two commands in a row
  2009. If X <> '///yyy zzz///'     Odb 'C' X
  2010.  
  2011. If PT = 'N' OutNull                    ; End of this test
  2012.  
  2013. ;===============================================================================
  2014. ; We're only reading in one line from input, so we can move to the next
  2015. ; parsing step (i.e. FileDone).
  2016. ;===============================================================================
  2017. NextStep
  2018.  
  2019. ;===============================================================================
  2020. ; Subroutines
  2021. ;===============================================================================
  2022. ; It's a good idea to put a Done command in front of all the Procedure
  2023. ; definitions, which are usually placed at the end of the script. For small
  2024. ; files the difference in speed is negligible, but if you are processing a
  2025. ; huge file it can save you a few seconds.
  2026. ;-------------------------------------------------------------------------------
  2027. Done
  2028.  
  2029. Procedure AddCntr
  2030.   Inc Cntr
  2031. End
  2032.  
  2033. Procedure AddCntr2
  2034.   Inc Cntr 2
  2035. End
  2036.  
  2037. Procedure ProcInProc1
  2038.   Begin
  2039.     Call AddCntr
  2040.   Again Cntr #< 3
  2041. End
  2042.  
  2043. Procedure ProcInProc2
  2044.   Begin X Len< 6
  2045.     Call AddCntr
  2046.     X = X 'A'
  2047.   Again
  2048. End
  2049.  
  2050. Procedure ParmProc
  2051.   TrimChar ParmProc 'A/'
  2052. End
  2053.  
  2054. Procedure EnsureOptionEmpty
  2055.   Caption = Parse EnsureOptionEmpty '' #13 'Cut'
  2056.   TrimChar EnsureOptionEmpty 'B '
  2057.   if EnsureOptionEmpty = '' Exit
  2058.   TrimChar Caption 'A&'
  2059.   Stop 'Please clear your ' Caption ' input box before running this script'
  2060. End